package com.hualan.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hualan.mapper.CourseMapper;
import com.hualan.pojo.Course;
import com.hualan.pojo.PageResult;
import com.hualan.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {
    @Autowired
    private CourseMapper courseMapper;
    @Override
    public PageResult queryAllCourse(String title, Integer page, Integer pageSize) {
        PageHelper.startPage(page,pageSize);
        List<Course> courseList = courseMapper.queryAllCourse(title);
        Page<Course> p=(Page<Course>)courseList;
        return new PageResult<>(p.getTotal(),p.getResult());
    }

    @Override
    public void deleteCourse(List<Integer> ids) {
        courseMapper.deleteCourseByIds(ids);
    }

    @Override
    public void saveCourse(Course course) {
        courseMapper.saveCourse(course);
    }

    @Override
    public Course getCourseById(Integer id) {
        return  courseMapper.getCourseById(id);
    }

    @Override
    public void updateCourse(Course course) {
        courseMapper.updateCourse(course);
    }
    @Override
    public List<Course> find(Integer id) {
        return courseMapper.find(id);
    }
}
